package adv3;

import java.util.HashMap;
import java.util.Map;

import adv2.Book;

public class MapTest {
	/**
	 * Map是键值对； key 不能重复(hashCode和equals),value不限制 不保证顺序
	 * HashMap,HashTable,TreeMap
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		Map map = new HashMap();
		map.put("狗", "dog");
		map.put("猫", "cat");
		map.put(null, "没有！");
		map.put("nothing", null);

		map.put("top1", new Book("干了这碗毒鸡汤", "文学", 2000));
		map.put(new Book("java从入门到放弃", "IT类", 1500), "这本书不错！");
		System.out.println(map.size());
		System.out.println(map);
		if (map.containsKey("nothing")) {
			Object r = map.get("nothing");
			System.out.println("nothing:" + r);
		} else {
			System.out.println("没有这个key");
		}
		if (map.containsKey(null)) {
			Object r = map.get(null);
			System.out.println("null:" + r);
		} else {
			System.out.println("没有这个key");
		}
		Object r = map.get("nothing");
		System.out.println(r);
		Object r2 = map.get("狗");
		System.out.println(r2);
		Object r3 = map.remove("top1");
		System.out.println(r3);
	}
}
